﻿using System;

namespace BO.Management.QueryBuilder
{
    public abstract class BaseQueryParameter
    {
        public String ParameterName { get; set; }
        public OperatorType Operator { get; set; }

        public String GetOperator()
        {
            switch (Operator)
            {
                case OperatorType.Equal:
                    return "=";
                case OperatorType.Like:
                    return "like";
                case OperatorType.GreatherOrEqual:
                    return ">=";
                case OperatorType.LessOrEqual:
                    return "<=";
                case OperatorType.Greather:
                    return ">";
                case OperatorType.Less:
                    return "<";
                default:
                    return "=";
            }
        }

        /// <summary>
        /// Normalize query parameter to handle quote issue
        /// </summary>
        /// <param name="parameter"></param>
        /// <returns></returns>
        public String NormalizeQueryParameter(String parameter)
        {

            //Quote modification
            //First ensure that if double quote is already set
            String value = parameter.Replace("''", "'");

            //Set double quote when we found single quote
            return value.Replace("'", "''");
        }

        public abstract Object GetValue();
    }

}
